package com.howard.core;

import com.howard.constants.DataSourceType;

/**
 *
 * 数据源管理
 * @author <a href="mailto:howard.he0329@gmail.com">Howard.He</a>
 *
 */
public class DataSourceManager {

	private DataSourceManager() {}

	private static ThreadLocal<DataSourceProvider> dataSourceProvider = new ThreadLocal<DataSourceProvider>() {
		@Override
		protected DataSourceProvider initialValue() {
			return new DataSourceProvider();
		}
	};

	public static void setDataSourceProvider(String dataSourceName, DataSourceType dataSourceType) {
		DataSourceProvider provider = dataSourceProvider.get();
		provider.setDataSourceName(dataSourceName);
		provider.setDataSourceType(dataSourceType);
	}

	public static String getDataSourceName() {
		return dataSourceProvider.get().dataSourceName;
	}

	public static DataSourceType getDataSourceType() {
		return dataSourceProvider.get().dataSourceType;
	}

	/**
	 *
	 * 数据源提供者
	 * @author <a href="mailto:howard.he0329@gmail.com">Howard.He</a>
	 *
	 */
	private static class DataSourceProvider {
		private String dataSourceName;
		private DataSourceType dataSourceType;

		private void setDataSourceName(String dataSourceName) {
			this.dataSourceName = dataSourceName;
		}

		private void setDataSourceType(DataSourceType dataSourceType) {
			this.dataSourceType = dataSourceType;
		}
	}
}
